package com.moyu.article.controller;

import com.alibaba.nacos.api.model.v2.Result;
import com.moyu.article.domain.board.dto.*;
import com.moyu.article.domain.board.vo.BoardHotVO;
import com.moyu.article.domain.board.vo.BoardVO;
import com.moyu.article.service.IBoardService;
import com.moyu.common.core.controller.BaseController;
import com.moyu.common.core.domain.R;
import com.moyu.common.core.domain.TableDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author 赵彦博
 * @Date 2025/3/29 19:05
 */
@RestController
@RequestMapping("/board")
public class BoardController extends BaseController {

    @Autowired
    private IBoardService boardService;

    @GetMapping("/list")
    public TableDataInfo getBoardList(BoardQueryDTO boardQueryDTO) {
        return getTableDataInfo(boardService.getBoardList(boardQueryDTO));
    }

    @PostMapping("/add")
    public R addBoard(@Validated @RequestBody BoardAddDTO boardAddDTO) {
        return toR(boardService.addBoard(boardAddDTO));
    }

    @PostMapping("/update")
    public R updateBoardService(@Validated @RequestBody BoardUpdateDTO boardUpdateDTO) {
        return toR(boardService.updateBoardService(boardUpdateDTO));
    }

    @DeleteMapping("/delete/{boardId}")
    public R deleteBoard(@PathVariable Long boardId) {
        return toR( boardService.deleteBoard(boardId));
    }

    @PostMapping("/batchUpdateSort")
    public R batchUpdateSort(@Validated @RequestBody List<BatchSortUpdateDTO> updateList) {
        return toR(boardService.batchUpdateSort(updateList));
    }

    @GetMapping("/getAllBoard")
    public TableDataInfo getAllBoard(BoardAllQueryDTO dto) {
        return getTableDataInfo(boardService.getAllBoard(dto));
    }

    @GetMapping("/getHotBoard")
    public List<BoardHotVO> getHotBoard() {
        return boardService.getHotBoard();
    }

    @GetMapping("/listByBoardId")
    public TableDataInfo listByBoardId(BoardDTO dto) {
        return getTableDataInfo(boardService.listByBoardId(dto));
    }

    @GetMapping("/detailByBoardId")
    public BoardVO detailByBoardId(@RequestParam("boardId")String boardId) {
        return boardService.detailByBoardId(boardId);
    }
}
